const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      integral_scheme: {
        Integral_Scheme_SerialNumber: "",
        Start_Date: "",
        End_Date: "",
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Children: {
          integral_scheme_detail: [
            {
              time_list: [],
              Integral_Scheme_Detail_SerialNumber: "",
              Integral_Scheme_SerialNumber: "",
              Member_Rights_SerialNumber: "",
              Integral_Day: "1",
              Integral_Day_Start: "",
              Integral_Day_End: "",
              Integral_Day_Magnification: "",
              Integral_Type_SerialNumber: "",
            }
          ],
          integral_scheme_storescope: [
            {
              Integral_Scheme_Storescope_SerialNumber: "",
              Integral_Scheme_SerialNumber: "",
              Store_SerialNumber: "",
            }
          ],
          integral_scheme_article: [
          ]
        }
      },
      form: {
        page: 1,
        limit: 5,
        Article_Name: "",
        Category_SerialNumber: JSON.stringify([]),
        Brand_SerialNumber: JSON.stringify([]),
      },
      in_store_info: [],
      integral_type_method: [],
      integral_type_index: 0,
      integral_type: [],
      commodityNum: [
      ],
      zhongli: [],
      tableData: [],
      pp: "",
      total: 0,
      Vip_identity_list: [],//身份列表
      rules: {
        Start_Date: [
          { required: true, message: '请输入开始时间', trigger: 'blur' },
        ],
        End_Date: [
          { required: true, message: '请输入结束时间', trigger: 'change' }
        ],

        pp: [
          { required: true, message: '请选择商品分类方式', trigger: 'blur' }
        ],
        zhongli: [
          { required: true, message: '请选择适用商品类', trigger: 'blur' }
        ],
      },
      Member_Rights_SerialNumber: [
        { required: true, message: '请选择会员身份', trigger: 'change' }
      ],
      Integral_Day_Magnification: [
        { required: true, message: '请选择积分倍率', trigger: 'change' }
      ],
      time_list: [
        { required: true, message: '请选择生效日期', trigger: 'change' }
      ],
      Integral_Type_SerialNumber: [
        { required: true, message: '请选择适用类别', trigger: 'blur' }
      ],
      Store_SerialNumber: [
        { required: true, message: '请选择适用店铺', trigger: 'blur' }
      ],
    }
  },
  mounted() {

  },
  methods: {
    //会员身份
    Vip_identity() {
      let _this = this;
      $.ajax({
        url: DomainName + '/getInquiryAction?token=' + $.cookie("token"),
        data: {
          Data: "member_rights_info"//身份,F
        },
        success: function (res) {
          _this.Vip_identity_list = res
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    time(item, e) {
      item.Integral_Day_Start = e[0];
      item.Integral_Day_End = e[1];
    },
    //删除
    handleDelete(row) {
      const index = this.integral_scheme.Children.integral_scheme_article.indexOf(row);
      this.integral_scheme.Children.integral_scheme_article.splice(index, 1);
    },
    //具体商品article_info
    article_info_methods() {
      let _this = this;
      if (this.pp === "category") {
        this.form.Category_SerialNumber = JSON.stringify(this.zhongli);
      } else {
        this.form.Brand_SerialNumber = JSON.stringify(this.zhongli);
      }
      _this.integral_scheme.Children.integral_scheme_article = [];
      $.ajax({//请求适用商品详情
        url: DomainName + '/getArticleInfoAction?token=' + $.cookie("token"),
        data: _this.form,
        success: function (res) {
          console.log(res);
          res.tableData.forEach(item => {
            _this.integral_scheme.Children.integral_scheme_article.push({
              Integral_Scheme_Article_SerialNumber: "",
              Integral_Scheme_SerialNumber: "",
              Article_SerialNumber: item.Article_SerialNumber,
              Picture_URL: item.Picture_URL,
              Category_Name: item.Category_Name,
              Brand_Name: item.Brand_Name,
              Article_Name: item.Article_Name,
            })
          });;
          _this.total = res.tableData.length;
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    // 选择商品
    commodity(e) {
      let _this = this;
      let com = "";
      if (e == "category") {
        com = "category"
      } else {
        com = "brand"
      }
      this.zhongli = [];
      this.commodityNum = [];
      $.ajax({//请求适用商品类(可多选)
        url: DomainName + '/getInquiryAction?token=' + $.cookie("token"),
        data: {
          Data: com,
          isNullEnterprise: true
        },
        success: function (res) {
          console.log(res);
          _this.commodityNum = res.map(obj => ({
            Category_Name: Object.values(obj)[1],
            Category_SerialNumber: Object.values(obj)[0]
          }));
          console.log(_this.commodityNum);
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    //筛选积分类型
    integral_type_methods(e) {
      // console.log(e);
      this.integral_type_method = this.integral_type.filter(item => item.Integral_Type_SerialNumber === e);
      // console.log(this.integral_type_method);
    },
    //查询积分类别
    //查询积分店铺
    get_store_info() {
      let _this = this;
      $.ajax({
        url: DomainName + '/getInquiryAction?token=' + $.cookie("token"),
        data: {
          Data: "store_info",
        },
        success: function (res) {
          // console.log(res);
          _this.in_store_info = res
          console.log(_this.in_store_info);
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/getInquiryAction?token=' + $.cookie("token"),
        data: {
          Data: "integral_type",
        },
        success: function (res) {
          // console.log(res);
          _this.integral_type = res
          console.log(_this.integral_type);
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val) {
      this.form.page = val;
    },
    // 新增身份
    add_ii_Applicable_identity() {
      this.integral_scheme.Children.integral_scheme_detail.push({
        Integral_Scheme_Detail_SerialNumber: "",
        Integral_Scheme_SerialNumber: "",
        Member_Rights_SerialNumber: "",
        Integral_Day: "1",
        Integral_Day_Start: "",
        Integral_Day_End: "",
        Integral_Day_Magnification: "",
        Integral_Type_SerialNumber: "",
        Row_Status: "",
        Operation_ID: "",
        Operation_Datetime: ""
      })
    },
    remove_ii_Applicable_identity() {
      if (this.integral_scheme.Children.integral_scheme_detail.length > 1) {
        this.integral_scheme.Children.integral_scheme_detail.pop()
      } else {
        this.$message({
          message: '不能在删除了',
          type: 'warning'
        })
      }
    },
    //新增店铺
    add_ii_Applicable_shop() {
      this.integral_scheme.Children.integral_scheme_storescope.push({
        Integral_Scheme_Storescope_SerialNumber: "",
        Integral_Scheme_SerialNumber: "",
        Store_SerialNumber: "",
        Row_Status: "",
        Operation_ID: "",
        Operation_Datetime: ""
      })
    },
    remove_ii_Applicable_shop() {
      if (this.integral_scheme.Children.integral_scheme_storescope.length > 1) {
        this.integral_scheme.Children.integral_scheme_storescope.pop()
      } else {
        this.$message({
          message: '不能在删除了',
          type: 'warning'
        })
      }
    },
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 表单验证通过，执行提交操作
          console.log('表单验证通过，执行提交操作');
        } else {
          // 表单验证失败，显示错误信息
          console.log('表单验证失败，请检查表单填写');
        }
      });
      // let _this = this;
      // $.ajax({
      //   url: DomainName + '/getAddAction?token=' + $.cookie("token"),
      //   data: {
      //     Data: JSON.stringify({ integral_scheme: [_this.integral_scheme] }),
      //   },
      //   success: function (res) {
      //     console.log(res);
      //   },
      //   complete: function (XMLHttpRequest) {
      //     _this.loading = false
      //     if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
      //       window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
      //     }
      //   }
      // })
    }
  },
  created() {
    this.get_store_info();
    this.Vip_identity();
    // this.commodity()
  }
})